// //
// Copyright (C) 2006 Pilitsyn Vasiliy <nexus@ablogic.ru>

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <qaction.h>
#include <qcanvas.h>
#include <qimage.h>
#include <qlabel.h>
#include <qtooltip.h>
#include <qsqldatabase.h>
#include <qstringlist.h>
#include <qtimer.h>
#include <qtoolbutton.h>
#include <qsqldatabase.h>
#include <qwidgetstack.h>
#include <qmainwindow.h>


#include "diagramline.h"
#include "devitem.h"
#include "cmdconsole.h"
#include "viewengine.h"
#include <qtabwidget.h>
#include "tabbar.h"
#include "thread.h"

// static const int ItemRtti = 1001;
// static const int lineRtti = 1002 ;



class Pinger : public QMainWindow
{
    Q_OBJECT
public:
    Pinger();
    
    void CreateButtons();

    bool SQLConnect();


public slots:
   
   void about();
   void closeApp();
   void hide_show();
   void createStatusBar();
   void updateCellIndicators();
   void configmenu();
   void timerTact();
   void stopMonitoring();
   void startMonitoring();
   void updateRecentFileItems();

   void setText_modLabel(const QString& sta);
   void setText_locationLabel(const QString& sta);
   void setText_formulaLabel(const QString& sta);

   void ExpImpDialog();

   void reinitButtons();
   
private slots:
    
   void pingall();
   void pingCurrentMap();

    void readSettings();
    void writeSettings();

    void newFile();
    void open();
    bool saveCurrentMap();
    bool saveAsCurrentMap();
    bool save(ViewEngine *);
    bool saveAs(ViewEngine *);
     
    void openRecentFile(int param);
    
    void selTaba(ViewEngine *);
    bool removeMap(ViewEngine *);
    
    void configdevice();
    void addLine();
    
protected:
      void closeEvent(QCloseEvent*);

signals:
      void sendMessadge(const QString &st);
      void setHideMsgWindow(int &);

      
private:
   QSqlDatabase* db;
   bool acct;
   int tEvent;
   QScrollView* scroll;
   ViewEngine* view;
   ViewEngine* tmp_map;
   QToolBar* ptb;
   QTabWidget* tabbar;
   bool maybeSave(ViewEngine *);
   bool maybeSaveAll();
   
   TabDialog* tabDialog;
   QPtrList<ViewEngine>  list;
   myprocess* proc;
   QPopupMenu* fileMenu;
   QPopupMenu* help;
   QPopupMenu* edit;
   enum { MaxRecentFiles = 7 };
   int recentFileIds[MaxRecentFiles];
   QPtrList<QString> tabList; 
   
   QAction    *simpleScaleAction;
   QAction    *actPing;
   QAction    *actStopMonitoring;
   QAction    *actRunMonitoring;
   QAction    *actNewMap;
   QAction    *actOpenMap;
   QAction    *actSaveMap;
   QAction    *actSaveAsMap;
   QAction    *actExpImpDialog;
   QAction    *actAddDevice;
   QAction    *actAddLine;
   QAction    *actAboutQtAct;
   QAction    *actAbout;
   QAction    *actPreferences;
   QAction    *actRemoveTabMap;
   QLabel     *modLabel;
   QLabel     *formulaLabel;
   QLabel     *locationLabel;


    QString colorBackGround;
    QString colorLinesColor;
    QString colorTextColor;
    QString colorSelectedColor;
    
    int MonitorPeriod;
    int NumberRetries;
    int DeviceMonitorPeriod;
    int HideMsgWindow;
    bool EnableMessages;

    QString FontMap;
    int FontMapSize;
    bool FontMapItalic;
    bool FontMapBold;
    bool counter;
    QTimer* ptimer;

    
    void loadFile(const QString &fileName);
    void saveFile(ViewEngine *);
    void setCurrentFile(const QString &fileName);
    QString strippedName(const QString &fullFileName);
    QString extensionName(const QString &fullFileName);
    QString curFile;
    QStringList recentFiles;
    QStringList counterTab;
   
    void restoreTabs(const QStringList &);
    void removeTabFromList(const QString &);
    void xm();
    void writeTabList();
};



#endif
